home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / utility / ffe101.zip / MOD.SWG / 0012_MDL.pas < prev    next >
Pascal/Delphi Source File  |  1996-09-04  |  18KB  |  403 lines

  1. ╔════════════════════════════════════════════════════════════════════════════╗
  2. ║                        THE SONGMODULE-FORMAT  (MDL)                   V1.1 ║
  3. ╚════════════════════════════════════════════════════════════════════════════╝
  4.  
  5. Offset Lenght Description
  6.  
  7.  000    004     "DMDL"; the four letters mark the mdl-format
  8.  004    001     version; the current version is 11h (=1.1)
  9.  005    ???     the different data-blocks are stored at this position
  10.  
  11. Some words to the format version-number:
  12. - if the low-nibble increases, there are extensions in the format, but old
  13.   loaders should be able to load the new modules (or most of them...)
  14. - if the high-nibble increases, there are changes in the format which make old
  15.   loaders unable to read the new songfiles
  16.  
  17. The MDL-songmodule-format is subdivided into the following blocks:
  18.  
  19. "IN"    infoblock; contains most songparameters, like speed, length etc.
  20. "ME"    songmessage; contains the songinformation from the composer
  21. "PA" c  pattern; contains the length, names and tracklists for every pattern
  22. "TR"    tracks; contains all the tracks for the pattern
  23. "II" n  instruments; contains all information for the used instruments
  24. "VE" n  volume-envelopes; contains the construction of all used vol-envelopes
  25. "PE" n  panning-envelopes; the same for the used pan-envelopes
  26. "FE" n1 frequency-envelopes; ...used frq-envelopes (LFO)
  27. "IS" c  sampleinfos; contains information for every used sample
  28. "SA"    samples; contains the sample-datas
  29.  
  30. [[ c  = blockstructure changes from v0.0 to v1.0 ]]
  31. [[ n  = new in version 1.0                       ]]
  32. [[ n1 = new in version 1.1                       ]]
  33.  
  34. The sequence of the blocks in a file is not fixed so they can be stored in any
  35. way. Digitrakker uses the descripted sequence.
  36.  
  37. The structure for every block is the same:
  38.  
  39. Offset Lenght Description
  40.  
  41.  000    002     "xx"; block-ID (example: "IN" for infoblock)
  42.  002    004     blocklength; this dword contains the length of the FOLLOWING
  43.         datas.
  44.  006 <blocklen> datas for this block...
  45.  
  46. The next block will be at offset (006 + <blocklength>).
  47.  
  48. ┌────────────────────────────────────────────────────────────────────────────┐
  49. │                          The Song-Infoblock  (IN)                          │
  50. └────────────────────────────────────────────────────────────────────────────┘
  51.  
  52. Offset Lenght Description
  53.  
  54.  000    002     "IN"; infoblock-ID
  55.  002    004     blocklenght
  56.  006    032     songname; name of the songmodule (filled with spaces [32])
  57.  038    020     composername; name of the song-composer
  58.  058    002     songlength; Digitrakker supports up to 255 songpositions
  59.  060    002     songrepeat
  60.  062    001     mainvolume (001-255)
  61.  063    001     song-speed (001-255)
  62.  064    001     beats per minute (004-255)
  63.  065    032     channel-information: bit 0-6 - panposition (0=left,127=right)
  64.                      bit 7   - 0=channel on, 1=channel off
  65.                 [number of channels = last active channel]
  66.  097  <snglen>  sequencer; contains the number of the pattern for every
  67.         songposition
  68.  ???  <chnnam>  the names for every channel (8 chars for one name).
  69.         <chnnam> = 8 * <number of channels>
  70.  
  71. ┌────────────────────────────────────────────────────────────────────────────┐
  72. │                            The Songmessage (ME)                            │
  73. └────────────────────────────────────────────────────────────────────────────┘
  74.  
  75. Offset Lenght Description
  76.  
  77.  000    002     "ME"; songmessage-ID
  78.  002    004     blocklenght
  79.  006    ???     songmessage; every line is closed with the CR-char (13). A
  80.         0-byte stands at the end of the whole text.
  81.  
  82. ┌────────────────────────────────────────────────────────────────────────────┐
  83. │                           The Patterndatas  (PA)                           │
  84. └────────────────────────────────────────────────────────────────────────────┘
  85.  
  86. Offset Lenght Description
  87.  
  88.  000    002     "PA"; patterndata-ID
  89.  002    004     blocklenght
  90.  006    001     number of pattern; values from 1 to 255 are possible
  91.  007  <patlar>  the datablocks for all saved pattern
  92.  
  93. The structure of one pattern-datablock:
  94.  
  95.  000    001    number of used channels (0-32)
  96.  001    001    patternlength-1; the actual digitrakker-version only
  97.         supports patterns with 64 rows (always 63 in this byte)
  98.  002    016    pattern-name (filled with [32])
  99.  018  <trklar>  tracksequencing-list
  100.         <trklar> = 2 * number of channels in this pattern
  101.  
  102. The tracksequencing-lists descripe which track is used as which voice in the
  103. pattern. The first word in this list is the number of the track at voice 0.
  104. The second is track for voice 1 and so on...
  105. As every track is saved independend, it is possible to save some discspace by
  106. this methode: If the song contains equal tracks at several positions in
  107. the patterns, these double tracks will only saved one time.
  108. Track 0 is not saved and represents an empty track.
  109.  
  110. ┌────────────────────────────────────────────────────────────────────────────┐
  111. │                            The Trackdatas  (TR)                            │
  112. └────────────────────────────────────────────────────────────────────────────┘
  113.  
  114. Offset Lenght Description
  115.  
  116.  000    002     "TR"; trackdata-ID
  117.  002    004     blocklenght
  118.  006    002     number of tracks
  119.  008    ???     track-datablocks; every trackdatablock is stored in this way:
  120.         Ofs.000 Len.002         length of the trackdatas
  121.             002 <trackdatalen>  datas for this track
  122.  
  123. Every track consists of 1-256 notepositions and every notposition contains
  124. 6 bytes:
  125.  
  126. byte 0              - note-value; 1 = C-0, 2 = C#0,..., 120 = B-9,
  127.               0 = nothing (---), 255 = key off (^^^)
  128. byte 1              - sample-number; 1-255; 0 = nothing
  129. byte 2              - volume; 1-255; 0 = no volume change
  130. byte 3, low nibble  - number of the first effect-command
  131. byte 3, high nibble - number of the second effect-command (commands "g"-"l"
  132.               get the numbers 1-6)
  133. byte 4              - databyte for the first effect-command
  134. byte 5              - databyte for the second effect-command
  135.  
  136. Digitrakker stores the tracks in a packed way. The structure of this very
  137. effective (!!!) packformat is the following:
  138.  
  139.      bit 76543210
  140. byte 0 - xxxxxxyy
  141.  
  142. if yy = 00 -> <xxxxxx>+1 is the number of the empty notepositions which are
  143.           following.
  144. if yy = 01 -> the last noteposition will be repeated <xxxxxx>+1 times.
  145. if yy = 10 -> the noteslot from position <xxxxxx> is copied to the actual
  146.           position.
  147. if yy = 11 -> the following datas will be put in the actual noteslot:
  148.         bit 2 = 1 -> note
  149.         bit 3 = 1 -> sample
  150.         bit 4 = 1 -> volume
  151.         bit 5 = 1 -> effectcommand numbers
  152.         bit 6 = 1 -> databyte for effect 1
  153.         bit 7 = 1 -> databyte for effect 2
  154.  
  155. To find out the number of notepositions in a track you should decrease a
  156. counter (startvalue: length of the packed trackdatas) while depacking.
  157. Every depacked track has to be filled out with 0-values up to position 256.
  158. When you copy the track into a pattern just take the number of positions you
  159. need for the pattern (if the pattern has a length of 64 positions only take
  160. the first 64 positions from the track).
  161.  
  162. ┌────────────────────────────────────────────────────────────────────────────┐
  163. │                           The Instruments (II)                             │
  164. └────────────────────────────────────────────────────────────────────────────┘
  165.  
  166. Offset Lenght Description
  167.  
  168.  000    002     "II"; intrument-ID
  169.  002    004     blocklenght
  170.  006    001     number of saved instruments; values from 0 to 255 are possible
  171.  007  <inslar>  the datablocks for all used instruments
  172.  
  173. The structure of one instrument-datablock:
  174.  
  175.  000    001     instrument-number; (1-255)
  176.  001    001    number of samples in instrument; (1-16)
  177.  001    032     instrument-name; the name of the instrument (filled with [32])
  178.  033  <is-len>  this block contains the infos for all defined samples in the
  179.         instrument; every info consist of 14 bytes, so
  180.         <is-len> = 14 * number of defined samples
  181.  
  182. The structure of one instrument-sample datablock:
  183.  
  184.  000    001     sample-number; (1-255)
  185.  001    001     playrange-end (0-119,0='c-0'); the last note for this sample;
  186.         a higher note uses one of the next samples
  187.  002    001     volume (1-255)
  188.  003    001     bit 0-5 -> volumeenvelope-number (0-63)
  189.         bit 6   -> flag, if volume is used
  190.         bit 7   -> flag, if volumeenvelope is used
  191.  004    001     panning (0-127)
  192.  005    001     bit 0-5 -> panningenvelope-number (0-63)
  193.         bit 6   -> flag, if panning is used
  194.         bit 7   -> flag, if panningenvelope is used
  195.  006    002     fadeout-speed (0-65535)
  196.  008    001     vibrator-speed (0-255)
  197.  009    001     vibrator-depth (0-255)
  198.  010    001     vibrator-sweep (0-255)
  199.  011    001     vibrator-form (0-2)
  200.  012    002     ** reserved ** (should be set to <0>)
  201.  
  202. ┌────────────────────────────────────────────────────────────────────────────┐
  203. │                         The Volume-Envelopes  (VE)                         │
  204. └────────────────────────────────────────────────────────────────────────────┘
  205.  
  206. Offset Lenght Description
  207.  
  208.  000    002     "VE"; volume-envelope-ID
  209.  002    004     blocklenght
  210.  006    001     number of saved vol-envelopes (0-64)
  211.  007  <ve-lar>  volume-envelope datas; a datablock contains 33 bytes, so
  212.         <ve-lar> = 33 * number of saved vol-envelopes;
  213.  
  214. The structure of one envelope-datablock:
  215.  
  216.  000    001     envelope-number; (0-63)
  217.  001    030     the positions of the 15 points are stored here; the first
  218.         byte is the x-distance from the last point (1-255; 0 means,
  219.         that no more points are defined; take 1 for the first point),
  220.                 the second byte is the y-position (0-63)
  221.  031    001     bit 0-3 -> sustain-point (0-14)
  222.         bit 4   -> flag, if sustain is on
  223.         bit 5   -> flag, if loop is on
  224.                 bit 6-7 -> ** reserved ** (should be set to <0>)
  225.  032    001     bit 0-3 -> loop-start (0-14)
  226.         bit 4-7 -> loop-end (0-14)
  227.  
  228. ┌────────────────────────────────────────────────────────────────────────────┐
  229. │                         The Panning-Envelopes (PE)                         │
  230. └────────────────────────────────────────────────────────────────────────────┘
  231.  
  232. Offset Lenght Description
  233.  
  234.  000    002     "PE"; panning-envelope-ID
  235.  002    004     blocklenght
  236.  006    001     number of saved pan-envelopes (0-64)
  237.  007  <pe-lar>  panning-envelope datas; a datablock contains 33 bytes, so
  238.         <pe-lar> = 33 * number of saved pan-envelopes
  239.         see at "VE" for the description of an envelope-datablock
  240.  
  241. ┌────────────────────────────────────────────────────────────────────────────┐
  242. │                        The Frequency-Envelopes (FE)                        │
  243. └────────────────────────────────────────────────────────────────────────────┘
  244.  
  245. Offset Lenght Description
  246.  
  247.  000    002     "FE"; frequency-envelope-ID
  248.  002    004     blocklenght
  249.  006    001     number of saved frq-envelopes (0-64)
  250.  007  <fe-lar>  frequency-envelope datas; a datablock contains 33 bytes, so
  251.                 <fe-lar> = 33 * number of saved frq-envelopes
  252.         see at "VE" for the description of an envelope-datablock
  253.  
  254. ┌────────────────────────────────────────────────────────────────────────────┐
  255. │                         The Sample-Infoblocks (IS)                         │
  256. └────────────────────────────────────────────────────────────────────────────┘
  257.  
  258. Offset Lenght Description
  259.  
  260.  000    002     "IS"; sampleinfo-ID
  261.  002    004     blocklenght
  262.  006    001     number of saved samples; values from 0 to 255 are possible
  263.  007  <samlar>  sample-infoblocks; a infoblock for one sample contains 59
  264.                 bytes, so <samlar> = 59 * number of saved samples
  265.  
  266. The structure of one sample-infoblock:
  267.  
  268.  000    001     sample-number; (1-255)
  269.  001    032     sample-name; the name of the sample (filled with [32])
  270.  033    008     filename of the sample
  271.  041    004     C-4 sample-frequency in hz
  272.  045    004     sample-length
  273.  049    004     sample-repeatstart
  274.  053    004     sample-repeatlength; if this value is set to 0, the sample
  275.         will not loop
  276.  057    001     ** not used ** (this was the volume in old v0.0-modules)
  277.  058    001     infobyte:
  278.         bit 0   -> 0=8 bit sample, 1=16 bit sample
  279.         bit 1   -> 0=forward looping, 1=bidirectional looping
  280.                 bit 2,3 -> packmethode (0=not packed, 1=8bit packing,
  281.                            2=16bit packing, 3=not defined)
  282.                 bit 4-7 -> ** reserved ** (should be set to <0>)
  283.  
  284. ┌────────────────────────────────────────────────────────────────────────────┐
  285. │                            The Sampledatas (SA)                            │
  286. └────────────────────────────────────────────────────────────────────────────┘
  287.  
  288. Offset Lenght Description
  289.  
  290.  000    002     "SA"; sampledata-ID
  291.  002    004     blocklenght
  292.  006    ???     sampledatas; samples are stored in numeric sequence
  293.  
  294. Unpacked samples are stored in signed form. Packmethode (1) is designed for
  295. 8 bit samples, Packmethode (2) for 16 bit samples. Methode (3) isn't defined
  296. in this version.
  297. A packed sample begins with a dword which contains the length of the
  298. following datastream.
  299.  
  300.  
  301. The description of the sample-packmethode (1) [8bit packing]:...
  302. ────────────────────────────────────────────────────────────────
  303.  
  304. This methode is based on the huffman-algorithm. It's an easy form, but very
  305. fast and effective on samples. The packed sample is a bit-datastream:
  306.  
  307.     Byte 0    Byte 1    Byte 2    Byte 3
  308. Bit 76543210  fedcba98  nmlkjihg  ....rqpo
  309.  
  310. A packed byte is stored in the following form:
  311.  
  312. xxxx10..0s => byte = <xxxx> + (number of <0>-bits between s and 1) * 16 - 8 ;
  313.           if s=1 then byte = byte xor 255
  314.  
  315. If there are no <0>-bits between the first bit (sign) and the <1>-bit, you
  316. have the following form:
  317.  
  318. xxx1s      => byte = <xxx> ; if s=1 then byte = byte xor 255
  319.  
  320. To depack one byte, you have to use the following algorithm:
  321. ┌────────────────────────────────────────────────────────────────────────────┐
  322. │       read bit                                                             │
  323. │       sign = bit                                                           │
  324. │       read bit                                                             │
  325. │       if bit = 1                                                           │
  326. │               then  read [3bits]                                           │
  327. │                     byte = [3bits]                                         │
  328. │                     goto next                                              │
  329. │               else  byte = 8                                               │
  330. │loop:  read bit                                                             │
  331. │       if bit = 0                                                           │
  332. │               then  byte = byte + 16                                       │
  333. │                     goto loop                                              │
  334. │               else  read [4bits]                                           │
  335. │                     byte = byte + [4bits]                                  │
  336. │next:   if sign = 1                                                         │
  337. │               then byte = byte xor 255                                     │
  338. └────────────────────────────────────────────────────────────────────────────┘
  339.  
  340. Two examples:
  341.  
  342. xxxx  s
  343. 1001101 = ( 9 + 1 * 16 - 8 ) xor 255 = 238
  344.  
  345. xxx s
  346. 01010 = 2
  347.  
  348. Note that the depacked bytes are delta values. To convert them to real data
  349. use this algorithm:
  350.  
  351. oldbyte = 0
  352. for sampleposition = 1 to samplelength
  353.     newbyte = byte [sampleposition] + oldbyte
  354.     byte [sampleposition] = newbyte
  355.     oldbyte = newbyte
  356. next sampleposition
  357.  
  358.  
  359. The description of the sample-packmethode (2) [16bit packing]:...
  360. ────────────────────────────────────────────────────────────────
  361.  
  362. This works as methode (1) but it only crunches every 2nd byte (the high-
  363. bytes of 16 bit samples). So when you depack 16 bit samples, you have to
  364. read 8 bits from the data-stream first. They present the lowbyte of the
  365. sample-word. Then depack the highbyte in the descripted way (methode [1]).
  366. Only the highbytes are delta-values. So take the lowbytes as they are.
  367. Go on this way for the whole sample!
  368.  
  369.  
  370. ┌────────────────────────────────────────────────────────────────────────────┐
  371. │                    ** Differences to older formats **                      │
  372. └────────────────────────────────────────────────────────────────────────────┘
  373.  
  374. Changes from v0.0 to v1.0:
  375. - block "PN" (patternnames) doesn't exist in v1.0-modules (patternnames now
  376.   stored in block "PA")
  377.   the old v0.0 structure of the "PN"-block:
  378.     000    002     "PN"; patternnames-ID
  379.     002    004     blocklenght
  380.     006  <patnam>  the names for every pattern (16 chars for one name).
  381.            <patnam> = 16 * <number of patterns>
  382. - structure of block "PA" changes completely
  383.   the old v0.0 structure of the "PA"-block:
  384.     000    002     "PA"; patterndata-ID
  385.     002    004     blocklenght
  386.     006    001     number of pattern; values from 1 to 255 are possible
  387.     007  <patlar>  tracksequencing-list for the used patterns;
  388.            <patlar> = 64 * number of patterns (32 words with the
  389.            tracknumbers for every pattern)
  390. - new blocks in v1.0-modules: "II" (instruments), "VE" (volume-envelopes) and
  391.   "PE" (panning-envelopes)
  392. - volumebyte (byte 57) in the sample-datablocks (block "IS") isn't used;
  393.   the C-4 sample-frequency increases from a word (2 bytes) to a dword (4
  394.   bytes), so one whole sample-infoblock has a length of 59 bytes
  395.  
  396. Extension from v1.0 to v1.1:
  397. - new block: "FE" (frequency-envelopes)
  398.  
  399.  
  400.  
  401.  
  402.  
  403.